<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="css/login.css" rel="stylesheet"/>
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script src="js/login.js"></script>
    <title>登录_重新设置密码</title>
    <style>
        #bt1,#bt3{
            display: none;
        }
        #bt2{
            display: block;
        }
    </style>
</head>
<body>
<div id="login">
    <div id="header">
        <img class="back" src="images/back.png" alt="">
    </div>
    <div id="content">
        <div id="fp">
            <strong>重新设置密码</strong>
        </div>
        <form action="" id="form">
            <input type="password" id="pas1" placeholder="请输入登录密码">
            <img src="images/open.png" alt="" id="bt1" class="img2">
            <img src="images/close.png" alt="" id="bt2" class="img2" >
            <input type="password" id="pas2" placeholder="请再次输入登录密码">
            <img src="images/open.png" alt="" id="bt3" class="img3">
            <img src="images/close.png" alt="" id="bt4" class="img3">
            <div id="msg"></div>
        </form>
        <div id="button">
            <button class="login">重置密码</button>
        </div>
    </div>
</div>

<script>
    $(function(){
        $("#form .img2").click(function(){
            if($("#pas1").attr("type")=="text"){
                $("#pas1").attr("type", "password");
                $('#bt1').hide();
                $("#bt2").show();
            }else{
                $("#pas1").attr("type", "text");
                $('#bt1').show();
                $("#bt2").hide();
            }
        });

        $("#form .img3").click(function(){
            if($("#pas2").attr("type")=="text"){
                $("#pas2").attr("type", "password");
                $('#bt3').hide();
                $("#bt4").show();
            }else{
                $("#pas2").attr("type", "text");
                $('#bt3').show();
                $("#bt4").hide();
            }
        });
    })
</script>

<script>
    $(function () {
        $(".back").click(function(){
            $(window).attr('location',"login_resetCode.html");
        });



        $(".login").click(function(){
            localStorage.password=$("#pas1").val();
            localStorage.password1=$("#pas2").val();
            console.log(localStorage.password);
            console.log(localStorage.password1);
            if(localStorage.password===''||localStorage.password1===''){
                // alert()
                $("#msg").html("密码不能为空");
            }else {
                if(localStorage.password===localStorage.password1){
                    console.log(localStorage.str);
                    console.log(localStorage.mobile);
                    $.ajax({
                        type: 'POST',
                        url: `${localStorage.top}api/user/resetpwd`,
                        data: {
                            mobile:localStorage.mobile,
                            newpassword:$("#pas1").val(),
                            captcha: localStorage.str,
                        },

                        success:function (data) {
                            console.log(data);
                            if(data.code == 1){
                                $(window).attr('location',"login.html");
                            }else {
                                $("#msg").html(data.msg);
                            }
                        }

                    });

                }else {
                    // alert("请输入一样的密码");
                    $("#msg").html("请输入一样的密码");
                }
            }

        });
    })
</script>
</body>
</html>